package com.tss.utils;

import java.awt.image.BufferedImage;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CertificateUtil {
//	private static String path="tss-manager-web/src/main/webapp/WEB-INF/certificate/";
//	private static String path="WEB-INF/certificate/";
	public static String createCertificate(String path,String name,String courseName,Date date){
		Pic tt = new Pic();  
//		String path = tt.loadPath();
		String fileName = Long.toString(((new Date()).getTime()))+".jpg";
		BufferedImage d = tt.loadImageLocal(path+"certificate.jpg");  
		BufferedImage bi = tt.modifyImage(d,name,410,322);
		tt.setFont("楷体",50);
		bi = tt.modifyImage(bi,courseName,500,390);
		tt.setFont("楷体",20);
//		tt.writeImageLocal(path+"fileName",tt.modifyImage(bi,"二〇一七年三月二十四日",650,640));
		DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
		String dateString = dateFormat.format(date);
		tt.writeImageLocal(path+fileName,tt.modifyImage(bi,dateString,700,640));
		//往图片上写文件  
		File file  = new File(path+fileName);  
		 if(file.exists()){
			 return fileName;
		 }else{
			 System.out.println(file.getAbsolutePath());
			 return null;
		 }
	}
}
